package action;

import java.util.HashMap;
import java.util.List;

import model.Dictionary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.github.miemiedev.mybatis.paginator.domain.PageList;

import action.base.BaseAction;
import service.DictionaryService;

@Controller
@Scope("prototype")
public class DictionaryAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private DictionaryService dictionaryService;
	private boolean success = false;
	private Dictionary dictionary;
	private PageList<HashMap<String, Object>> pageList;
	private List<HashMap<String, Object>> list;
	private int total;

	public String queryPage() {
		int limit = super.getParameterInt("limit");
		int page = super.getParameterInt("page");
		String str = super.getParameterStr("query");
		pageList = dictionaryService.queryPage(page, limit, str);
		setTotal(pageList.getPaginator().getTotalCount());
		return "queryPage";
	}

	public String saveOrUpdate() {
		dictionaryService.saveOrUpdate(dictionary);
		success = true;
		return "success";
	}

	public String listAll() {
		list = dictionaryService.listAll();
		success = true;
		return "list";
	}

	public String delete() {
		String ids = super.getParameterStr("ids");
		dictionaryService.delete(ids);
		success = true;
		return "success";
	}

	public DictionaryService getDictionaryService() {
		return dictionaryService;
	}

	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}

	public Dictionary getDictionary() {
		return dictionary;
	}

	public void setDictionary(Dictionary dictionary) {
		this.dictionary = dictionary;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public PageList<HashMap<String, Object>> getPageList() {
		return pageList;
	}

	public void setPageList(PageList<HashMap<String, Object>> pageList) {
		this.pageList = pageList;
	}

	public List<HashMap<String, Object>> getList() {
		return list;
	}

	public void setList(List<HashMap<String, Object>> list) {
		this.list = list;
	}

}
